package converter.util


class ArtifactMapBuilder {

	public Map buildArtifactMapForFolder(File dir) {
		Map map = [:]
		PomFinder pf = new PomFinder()
		List allPoms = pf.findAllPoms(dir)
		allPoms.each { File pomFile ->
			println "Processing pom $pomFile"
			String key = genKey(pomFile)
			map[key] = pomFile
		}
		return map
	}

	private String genKey(File pomFile) {
		EnvRetriver er = new EnvRetriver()
		EffectivePomProducer util = new EffectivePomProducer(er.getEnvMap())
		File effectivePom = util.getEffectivePom(pomFile)
		def project = new XmlSlurper().parse(effectivePom)
		return "\"" + project.groupId.text() + ":" + project.artifactId.text() + "\""
	}
}
